<?php

namespace app\http\middleware;

use think\facade\Request;

// 小程序的中间件
class Web
{
    public function handle($request, \Closure $next, $name)
    {
        $token = Request::header("token");
        $user = model('user');
        $info = $user->where(['token'=>$token])->find();
        if(empty($token) || empty($info)) {
          return apiError('非法登录请求',[], 4000);//账户不合法 4000状态
        }
        $request->user_id = $info['id']; // 携带账户ID
        return $next($request);
    }
}